<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录界面</title>
    <link rel="stylesheet" href="../css/login.css">
    <script>
        // 阻止表单默认提交并使用 fetch 进行异步提交
        function submitForm(event) {
            event.preventDefault(); // 阻止表单默认提交

            fetch('http://121.40.201.6/login.php', {
                method: 'POST',
                body: new URLSearchParams(new FormData(document.querySelector('form')))
            })
            .then(response => {
                if (response.ok) {
                    window.location.href = "../html/mine_new.html"; // 跳转到首页
                } else {
                    alert('登录失败!请重新登录');
                    window.location.href = "../html/login.html"; // 跳转回登录页
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('登录失败!请重新登录');
                window.location.href = "../html/login.html"; // 跳转回登录页
            });
        }
    </script>
</head>

<body>
    <div class="content">
        <div class="title">YonBIP登录页面</div>
        <form onsubmit="submitForm(event)">
            <input type="text" placeholder="账号" name="username" required>
            <input type="password" placeholder="密码" name="password" required>
            <button type="submit" class="btn">登录</button>
        </form>  
        <span>没有账号?<a href="#">注册</a></span>
    </div>

    <div class="square">
        <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <div class="circle">
        <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
</body>

</html>
